//
//  LJ_App_View.m
//  UIKIit_APPS
//
//  Created by 李竞 on 16/1/25.
//  Copyright © 2016年 lionjing. All rights reserved.
//

#import "LJ_App_View.h"


@implementation LJ_App_View

-(void)setApp_Model:(LJ_App_Model *)app_Model{

    // model :
    _app_Model = app_Model ;

    // icon :
    _app_icon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:app_Model.icon]];

    // label:
    _app_desc = [[UILabel alloc]init];
    _app_desc.text = app_Model.name ;
}



- (void)drawRect:(CGRect)rect {
    self.backgroundColor = [UIColor whiteColor];

    float view_W = self.frame.size.width ;
    float view_H = self.frame.size.height ;



    //添加文字描述:
    CGRect desc_rect = CGRectMake(0, view_W, view_W, 10);
    self.app_desc.frame = desc_rect;
    [self addSubview:self.app_desc ];
    self.app_desc.backgroundColor = [UIColor whiteColor];
    self.app_desc.font = [UIFont systemFontOfSize:13.0];
    [self.app_desc sizeToFit];

    //添加APP图片:
    CGRect icon_rect = CGRectMake(0, 0, view_W, view_W);
    self.app_icon.frame = icon_rect ;
    self.app_icon.backgroundColor = [UIColor whiteColor];

    [self addSubview:self.app_icon];

    self.backgroundColor = [UIColor redColor];



    //添加按钮:
    CGRect download_rect = CGRectMake(0, CGRectGetMaxY(self.app_desc.frame), view_W, (view_H - CGRectGetMaxY(self.app_desc.frame)));

    self.app_downLoad = [[UIButton alloc]initWithFrame:download_rect];

    [self addSubview:self.app_downLoad];
    [self.app_downLoad setBackgroundImage:[UIImage imageNamed:@"buttongreen"] forState:UIControlStateNormal];
    [self.app_downLoad setBackgroundImage:[UIImage imageNamed:@"buttongreen_highlighted"] forState:UIControlStateHighlighted];
    [self.app_downLoad setBackgroundImage:[UIImage imageNamed:@"buttongreen_highlighted"] forState:UIControlStateDisabled];
    //    self.app_downLoad.titleLabel.text = self.app_downLoad.enabled ? @"下载" : @"已下载" ;
    self.app_downLoad.titleLabel.text = [NSString stringWithFormat:@"ASDFASDF"] ;
    [self.app_downLoad setTitle:@"下载" forState:UIControlStateNormal];
    [self.app_downLoad setTitle:@"已下载" forState:UIControlStateDisabled];

    self.app_downLoad.titleLabel.font = [UIFont systemFontOfSize:13.0];


    //添加按钮点击事件 :

    [self.app_downLoad addTarget:self.LJ_VC action:@selector(BTN_Click:) forControlEvents:UIControlEventTouchUpInside];






   }
-(void)BTN_Click:(UIButton *)btn{
    if ([self.delegate respondsToSelector:@selector(Do_After_Btn_Clicked:)] ) {
        [self.delegate Do_After_Btn_Clicked:btn];
    }
}


@end
